forked from Py-Contributors/awesomeScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremover.py
More file actions
25 lines (21 loc) · 693 Bytes
/
remover.py
File metadata and controls
25 lines (21 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Title :- Trailing Whitespace Remover
# Importing Argument Parser
import argparse
# Creating Argument Parser
parser = argparse.ArgumentParser(
description="Remove Trailing Whitespaces from files."
)
parser.add_argument(
"files",
type=str,
nargs="+",
help="Files to remove trailing whitespace from."
)
args = parser.parse_args()
for fname in args.files: # iterating over each file provided
# remove trailing characters from each line
lines = [i.rstrip() for i in open(fname, "r").readlines()]
with open(fname, "w"):
pass # truncate to remove text from file
with open(fname, "w") as f:
f.write("\n".join(lines)) # write new clean text